package com.sunnada.edu.system.pub.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sunnada.edu.system.pub.common.AppContext;
import com.sunnada.edu.system.pub.dao.PubDao;

public class AppIniXml {
	public static HashMap<String, String> getParams(Class clazz) {
		ClassLoader cl = clazz.getClassLoader();
		InputStream input = cl.getResourceAsStream("appini.xml");
		String sConfigFileName = cl.getResource("appini.xml").toString();
		cl = null;
		try {
			byte[] aContent = new byte[input.available()];
			input.read(aContent);
			input.close();
			String sContent = new String(aContent);
			XmlParse xml = new XmlParse();
			if (!xml.bGetXML(sContent)) {
				System.out.println(xml.ErrMsg);
			}
			int iNum = xml.GetNameNum("sock");
			// 设置数组
			String[] FHost = new String[iNum];
			String[] FPort = new String[iNum];
			String[] FName = new String[iNum];
			String[] FKey = new String[iNum];
			String[] serurl = new String[iNum];
			OutputStream[] FOutputStream = new OutputStream[iNum];
			for (int i = 0; i < iNum; i++) {
				FHost[i] = xml.sGetValueByName("host", i);
				FPort[i] = xml.sGetValueByName("port", i);
				FName[i] = xml.sGetValueByName("name", i);
				FKey[i] = xml.sGetValueByName("key", i);
				serurl[i] = xml.sGetValueByName("serurl", i);
			}
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("host", FHost[0]);
			map.put("port", FPort[0]);
			map.put("name", FName[0]);
			map.put("key", FKey[0]);
			map.put("serurl", serurl[0]);
			PubDao dao = AppContext.getInstance().getPubDao();
			/*
			 * List l = (List<?>)dao.selectList(
			 * "select c_value v from j_config where c_code='istest'");
			 * if(l!=null&&l.size()>0){ String s =
			 * (String)((Map)l.get(0)).get("V"); if("1".equals(s)){
			 * map.put("host","10.142.145.12"); map.put("port","9001");
			 * map.put("name","/Inter_GMINI/GMini");
			 * map.put("key","6f73040d7c2b32837c7fa66ec5e36e1d"); }else
			 * if("2".equals(s)){ map.put("host","10.142.145.12");
			 * map.put("port","9001");
			 * map.put("name","/Inter_GMINI_TEST/GMini");
			 * map.put("key","1234567"); } }
			 */
			return map;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
